package com.example.bookstore;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;

public class BookAdapter extends ArrayAdapter<Book> {
    private int resourceId;
    public BookAdapter( Context context, int textViewResourceId,List<Book> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        Book book =getItem(position);
        View view=LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        TextView BookName=(TextView) view.findViewById(R.id.BookName);
        TextView BookCategory=(TextView) view.findViewById(R.id.BookCategory);
        TextView BookPrice=(TextView) view.findViewById(R.id.BookPrice);

        BookName.setText(book.getName());
        BookCategory.setText(book.getCategory());
        BookPrice.setText(book.getPrice());
        return view;
    }
}
